home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / music / patchlib.arc / PATCHSRC.ARC / CURSES.C < prev    next >
Text File  |  1985-11-20  |  2KB  |  138 lines

  1.  
  2. #include    <curses.h>
  3.  
  4. #define    printf    print
  5.  
  6. static char    kbd_mess[2] = {
  7.             DISABLE_MOUSE,
  8.             SET_REL_MOUSE
  9.         };
  10.  
  11. static int    save_pallette[16];
  12.  
  13. init_curses()
  14. {
  15.  
  16. int    i;
  17. int    pallette[16];
  18.  
  19.     for (i=0; i<16; i++) save_pallette[i] = Setcolor(i, -1);
  20.     for (i=0; i<16; i++) pallette[i] = 0xffff;
  21.     pallette[0] = 0;
  22.     Setpallete(pallette);
  23.     Vsync();
  24.     Ikbdws(0, kbd_mess);
  25.     scr_func(HIDE_CURS);
  26.     scr_func(CLEAR_SCR);
  27.     Cursconf(2, 0);
  28.     scr_func(SHOW_CURS);
  29. }
  30.  
  31. curses_cleanup()
  32. {
  33.     scr_func(HIDE_CURS);
  34.     Ikbdws(0, kbd_mess+1);
  35.     if (Getrez() < 2)
  36.         Setpallete(save_pallette);
  37. }
  38.  
  39. pos_cursor(x, y)
  40. int    x, y;
  41. {
  42.     char out;
  43.  
  44.     scr_func(POS_CURS);
  45.     out = y + 32;
  46.     char_out(out);
  47.     out = x + 32;
  48.     char_out(out);
  49. }
  50.  
  51. scr_func(func)
  52. char    func;
  53. {
  54.     char_out(27);
  55.     char_out(func);
  56. }
  57.  
  58. char_out(chrout)
  59. char    chrout;
  60. {
  61.     while(!Cconos());
  62.     Cconout(chrout);
  63. }
  64.  
  65. int get_str(string)
  66. unsigned char    *string;
  67. {
  68.     unsigned char    key, *str_pos;
  69.  
  70.     str_pos = string;
  71.     do {
  72.         key = Crawcin();
  73.         if (key < 32 || key == 127) 
  74.             switch ((int) key) {
  75.             case ESCAPE:
  76.                 *str_pos = '\0';
  77.                 return(-1);
  78.                 break;
  79.             case BACKSPACE:
  80.             case DELETE:
  81.                 if (str_pos > string) {
  82.                     erase_char();
  83.                     str_pos--;
  84.                 } else {
  85.                 char_out(BELL);
  86.                 }
  87.                 break;
  88.             case CARRIAGE_RETURN:
  89.                 *str_pos = '\0';
  90.                 return((int)((long)str_pos - (long)string));
  91.                 break;
  92.             case DEL_WORD:
  93.                 do {
  94.                     if (str_pos == string) char_out(BELL);
  95.                     else {
  96.                         erase_char();
  97.                         str_pos--;
  98.                         if (*(str_pos-1) == ' ') break;
  99.                     }
  100.                 } while (str_pos > string);
  101.                 break;
  102.             case DEL_LINE:
  103.             case CANCEL:
  104.                 if (str_pos == string) char_out(BELL);
  105.                 else while (str_pos > string) {
  106.                     erase_char();
  107.                     str_pos--;
  108.                 }
  109.                 break;
  110.             default:
  111.                 char_out(BELL);
  112.                 break;
  113.             }
  114.         else {
  115.             char_out(key);
  116.             *str_pos++ = key;
  117.         }
  118.     } while (TRUE);
  119. }
  120.  
  121. erase_char()
  122. {
  123.     scr_func(BACK_CURS);
  124.     char_out(' ');
  125.     scr_func(BACK_CURS);
  126. }
  127.  
  128. stderr(message)
  129. char    *message;
  130. {
  131.     scr_func(CLEAR_SCR);
  132.     printf("%s\n\r", message);
  133.     printf("... Hit any key to exit\n\r");
  134.     wait();
  135.     curses_cleanup();
  136.     exit(-1);
  137. }
  138. ə